package com.sm.appbase.example.ui;

import com.sm.appbase.base.basemvp.BaseModel;
import com.sm.appbase.base.basemvp.BasePresenter;
import com.sm.appbase.base.basemvp.BaseView;
import com.sm.appbase.example.UserInfo;
import com.sm.appbase.example.net.DemoRetrofitClient;
import com.sm.appbase.net.base.ApiSubscriber;
import com.sm.appbase.net.base.BaseResult;
import com.sm.appbase.net.base.Optional;

import io.reactivex.Observable;

public interface ExampContract {
    interface View extends BaseView {
        void loginResultSuc(UserInfo object);
    }

    class Model extends BaseModel {
        Observable<BaseResult<UserInfo>> login(String userName, String password) {
            return DemoRetrofitClient.getInstance().getAccountApi().login(userName, password);
        }
    }

    class Presenter extends BasePresenter<View> {
        void login(String userName, String passord) {
            apply(new Model().login(userName, passord))
                    .subscribe(new ApiSubscriber<Optional<UserInfo>>(mView, this) {
                        @Override
                        public void onNext(Optional<UserInfo> userInfoOptional) {
                            super.onNext(userInfoOptional);
                            mView.loginResultSuc(userInfoOptional.getIncludeNull());
                        }
                    });
        }
    }
}
